package 笔试.华为.线上笔试;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// 75
public class 二叉树去除重复的树节点 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] source = new int[n];
        for (int i = 0; i < n; i++) {
            source[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int[] remove = new int[m];
        for (int i = 0; i < m; i++) {
            remove[i] = sc.nextInt();
        }
        solve(source, remove);
    }

    private static void solve(int[] source, int[] remove) {
        HashMap<Integer, Integer> map = new HashMap<>();
        ArrayList<ArrayList<Integer>> level = new ArrayList<>();
        ArrayList<Integer> temp = new ArrayList<>();
        int dept = 0;
        for (int i = 0; i < remove.length; i++) {
            if ((2 << dept) - 1 == i) {
                level.add(new ArrayList<>(temp));
                temp.clear();
                dept++;
            }
            temp.add(remove[i]);
        }
        level.add(temp);
        dept = 0;
        for (int i = 0; i < source.length; i++) {
            if ((2 << dept) - 1 == i) {
                dept++;
            }
            if (dept < level.size()) {
                ArrayList<Integer> curDept = level.get(dept);
                if (curDept.contains(source[i])) {
                    curDept.remove((Integer) source[i]);
                    continue;
                }
            }
            map.put(source[i], map.getOrDefault(source[i], 0) + 1);
        }
        ArrayList<Map.Entry> list = new ArrayList<>(map.entrySet());
        list.sort(((o1, o2) -> {
            if (o1.getValue() != o2.getValue()) {
                return -((int) o1.getValue() - (int) o2.getValue());
            } else {
                return -((int) o1.getKey() - (int) o2.getKey());
            }
        }));
        for (int i = 0; i < list.size(); i++) {
            System.out.printf("%d", (int) list.get(i).getKey());
        }
    }
}
